<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
  <!ENTITY dc "http://purl.org/dc/elements/1.1/">
  <!ENTITY dcterms "http://purl.org/dc/terms/">
  <!ENTITY foaf "http://xmlns.com/foaf/0.1/">
  <!ENTITY a "http://xmlns.heustics.org/schema/myelin/0.1/">
  <!ENTITY m "http://xmlns.heustics.org/ontology/myelin/0.1/">
]>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:a="http://xmlns.heustics.org/schema/myelin/0.1/"
  xmlns:l="http://xmlns.heustics.org/schema/i18n/0.1/"
  exclude-result-prefixes="xsl l a"
>   
  <xsl:template match="a:imts" mode="a:select">
    <xsl:param name="selected"/>
    <xsl:param name='imt-l10n'/>
    <xsl:param name='name' select="'imt'"/>
    <select name="{$name}">
      <xsl:apply-templates mode="a:select">
        <xsl:with-param name="selected" select="$selected"/>
        <xsl:with-param name="imt-l10n" select="$imt-l10n"/>
      </xsl:apply-templates>
    </select>
  </xsl:template>
  
  <xsl:template match="a:content-type" mode="a:select">
    <xsl:param name="imt-l10n"/>
    <xsl:param name="selected"/>
    <xsl:variable name="mime" select="@mime"/>
    <xsl:variable name="ct-l10n" select="$imt-l10n/l:context[@name=$mime]/*"/>
    <optgroup label="{$imt-l10n/l:gentext[@key=$mime]}">
      <xsl:apply-templates mode="a:select">
        <xsl:with-param name="ct-l10n" select="$ct-l10n"/>
        <xsl:with-param name="selected" select="$selected"/>
        <xsl:with-param name='ct-mime' select='$mime'/>
      </xsl:apply-templates>
    </optgroup>
  </xsl:template>
  
  <xsl:template match="a:subtype" mode="a:select">
    <xsl:param name="ct-l10n"/>
    <xsl:param name="selected"/>
    <xsl:param name='ct-mime'/>
    <xsl:variable name='st-mime' select='@mime'/>
    <xsl:variable name='mime' select="concat($ct-mime,'/',$st-mime)"/>
    <option value='{$mime}'>
      <xsl:if test='$selected = $mime'>
        <xsl:attribute name='selected'>selected</xsl:attribute>
      </xsl:if>      
      <xsl:value-of select='$ct-l10n[@key=$st-mime]'/>
    </option>
  </xsl:template>
 
</xsl:stylesheet>

